#include <stdio.h>
#include <stdlib.h>

// open,read
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

// int main(int argc, char* argv[])
int main()
{
    char buf[1024];
    int fd;
    char test_file[32] = "test.log";
    fd = open(test_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
    if (fd < 0)
    {
        perror("打开文件失败");
        exit(0);
    }

    // 写
    int len = 1;
    for (int i = 0; i < 10; i++) {
        len = snprintf(buf, sizeof(buf) - 1, "this test msg %d\n", i);
        len = write(fd, buf, len);
    }
    close(fd);

    return 0;
}
